import requests
import logging

class Test1():
    uid=""
    sid=""
    def setup_method(self):
        print("初始化环境")
    def teardown_method(self):
        print("恢复环境")

    #登录
    def test_dl(self):
        try:
            url="http://10.59.9.18/small/user/v1/login"
            body={"phone":"13811033965","pwd":"123456Aa"}
            headers={"Content-Type":"application/json"}
            r=requests.post(url=url,json=body,headers=headers)
            print(r.json())
            Test1.uid = r.json()["result"]["userId"]
            Test1.sid = r.json()["result"]["sessionId"]
        except Exception as e:
            logging.info(e)
        assert r.status_code == 200

    #首页商品信息列表
    def test_syspxxlb(self):
        try:
            url="http://10.59.9.18/small/commodity/v1/commodityList"
            r=requests.get(url=url)
            print(r.json())
        except Exception as e:
            logging.info(e)
        assert r.status_code == 200

    #查看商品详情
    def test_ckspxq(self):
        try:
            url="http://10.59.9.18/small/commodity/v1/findCommodityDetailsById?commodityId=1004"
            headers={"userId":Test1.uid,"sessionId":Test1.sid}
            r=requests.get(url=url,headers=headers)
            print(r.json())
        except Exception as e:
            logging.info(e)
        assert r.status_code == 200

    #创建订单
    def test_cjdd(self):
        try:
            url="http://10.59.9.18/small/order/verify/v1/createOrder"
            headers={"userId":Test1.uid,"sessionId":Test1.sid}
            body={"orderInfo":"[{“commodityId”:21,”amount”:1}]","totalPrice":"189","addressId":"1"}
            r=requests.post(url=url,headers=headers,json=body)
            print(r.json())
        except Exception as e:
            logging.info(e)
        assert r.status_code == 200